package com.jic.interaction.ChinaPost.service.impl;

import com.alibaba.fastjson.JSON;
import com.jic.interaction.ChinaPost.service.UserConsumeDetailService;
import com.jic.interaction.common.utils.HttpClientUtil;
import com.jic.interaction.ChinaPost.model.entity.UserConsumeDetail;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

/**
 * @ClassName UserConsumeDetailServiceImpl
 * @Description TODO
 * @Author 陈鸿锋
 * @Date 2020/11/5 14:33
 * @Version 1.0
 **/
@Service
@Slf4j
public class UserConsumeDetailServiceImpl implements UserConsumeDetailService {

    @Value("${route.value}")
    private String url;

    /*
     * @Author chengpunan
     *@Package com.jic.interaction.service.impl
     *ClassName UserConsumeDetailServiceImpl
     * @Description  //TODO  用户消费明细查询
     * @Date 11:08 2020/11/10
     * @Param UserConsumeDetail
     * @return
     * @Version:1.0
     **/
    @Override
    public UserConsumeDetail getConsumeDetail(UserConsumeDetail userConsumeDetail) throws InterruptedException, ExecutionException, IOException {
        log.info("用户消费明细查询参数入参，{}", com.alibaba.fastjson.JSONObject.toJSONString(userConsumeDetail));
        String url=this.url+"/m/dbs-front/user/queryConsumeDetail";
        //TODO 必输校验
        //业务参数
        JSONObject jsonObject = JSONObject.fromObject(userConsumeDetail);
        //调用第三方接口返回数据
        String param = HttpClientUtil.requestPath(url, null,jsonObject.toString());
        log.info("用户消费明细查询结束");
        UserConsumeDetail userConsumeDetail1 = JSON.parseObject(param, UserConsumeDetail.class);
        return userConsumeDetail1;
    }
}
